package com.joysuch.wwyt.mh.controller;

import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.mh.bean.MhHazardChemProductBean;
import com.joysuch.wwyt.mh.bean.MhHazardChemicalProductSearchBean;
import com.joysuch.wwyt.mh.bean.MhMajorHazardChemProductBean;
import com.joysuch.wwyt.mh.service.MhHazardChemicalProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/mh/chem-product")
@Api(tags = "/mh/chem-product 危化品")
public class MhHazardChemicalProductController {

    @Autowired
    private MhHazardChemicalProductService hazardChemicalProduct;

    @GetMapping("/list")
    @ApiOperation(value = "危化品-查询", response = MhHazardChemProductBean.class)
    public ResultBean list(Pageable page, MhHazardChemicalProductSearchBean searchBean) {
        return hazardChemicalProduct.findAll(page,searchBean);
    }

    @GetMapping("/page")
    public ResultBean page(Pageable pageable, MhHazardChemicalProductSearchBean searchBean) {
        return hazardChemicalProduct.findAll(pageable,searchBean);
    }

    @PostMapping("/save")
    @ApiOperation(value = "危化品-新增", response = MhHazardChemProductBean.class)
    public ResultBean add(@RequestBody @Valid MhHazardChemProductBean mhHazardChemProductBean) {
        hazardChemicalProduct.add(mhHazardChemProductBean);
        return ResultBean.defaultSuccessResult();
    }

    @PostMapping("/edit")
    @ApiOperation(value = "危化品-修改", response = MhHazardChemProductBean.class)
    public ResultBean edit(@RequestBody @Valid MhHazardChemProductBean mhHazardChemProductBean) {
        hazardChemicalProduct.edit(mhHazardChemProductBean);
        return ResultBean.defaultSuccessResult();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "危化品-删除", response = MhHazardChemProductBean.class)
    public ResultBean del(Long id) {
        hazardChemicalProduct.delete(id);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("/findById")
    @ApiOperation(value = "危化品-查看", response = MhMajorHazardChemProductBean.class)
    public ResultBean findById(Long id) {
        MhMajorHazardChemProductBean bean = hazardChemicalProduct.findById(id);
        return ResultBean.success(bean);
    }


}
